/*
 * MemoryDataItem.java
 *
 * Created on February 28, 2004, 8:14 AM
 */

package org.infoset.xml.memory;

import org.infoset.xml.*;

/**
 *
 * @author  alex
 */
public abstract class MemoryTextDataItem extends MemoryItem implements Data, Text,Typed {

   protected String value;
   protected Object data;
   protected TypeDefinition typeDefinition;
   protected Name typeName;
   
   /** Creates a new instance of MemoryDataItem */
   public MemoryTextDataItem(Infoset infoset,Parent origin) {
      super(infoset,0,origin);
      this.value = null;
      this.data = null;
      this.typeDefinition = null;
      this.typeName = null;
   }
   
   public Object getTypedValue() {
      return data;
   }
   
   public void setTypedValue(Object dataValue) {
      data = dataValue;
      if (data!=null) {
         value = data.toString();
      }
   }
   
   public String getNormalizedText() {
      return value.trim();
   }
   
   public String getText() {
      return value;
   }
   
   public void setText(String textValue) {
      value = textValue;
      data = null;
   }
   
   public TypeDefinition getTypeDefinition() {
      return typeDefinition;
   }
   
   public void setTypeDefinition(TypeDefinition typeDef) {
      typeDefinition = typeDef;
      typeName = typeDef.getName();
   }
   
   public Name getTypeName() {
      return typeName;
   }
   
   public void setTypeName(Name typeName) {
      this.typeName = typeName;
      this.typeDefinition = null;
   }
   
}
